home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / routing / routed-config.frm.z / routed-config.frm
Encoding:
Text File  |  2002-06-12  |  9.3 KB  |  333 lines

  1. #!/usr/bin/perl5
  2. #
  3. # routed-config.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: routed-config.frm,v 1.36 1997/11/17 19:10:00 shotes Exp $
  21.  
  22. *MIMETRIC  =  0;
  23. *MAXMETRIC = 16;
  24.  
  25. BEGIN { require "/usr/WebFace/lib/CGI.pm"; import CGI; }
  26. require "/usr/OnRamp/lib/OnRamp.pm";
  27. require "/usr/OnRamp/lib/java.pm";
  28.  
  29. $query = new CGI;
  30.  
  31. $conf = "/etc/config/routed.options";
  32. $title = "Dynamic Routing";
  33. $help_page = "routed-config-help.html";
  34.  
  35. if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla\/2/) { $br_index = 1; }
  36. else { $br_index = 0; }
  37.  
  38. $js =
  39. "br_index = $br_index;
  40. $js_standard
  41. $js_error_box
  42. $js_help
  43. $js_ip
  44. $js_filename
  45. function checkForm(form) {
  46.     if (form.enable[br_index].checked) {
  47.         if (form.logf.value != \"\")
  48.             if (!testFilename(form.logf)) return (false);
  49.         if (!testAddress(form.net)) return (false);
  50.         if (!testInt(form.metric)) return (false);
  51.     }
  52.     return (true);
  53. }
  54. function testInt(Ctrl) {
  55.     if (Ctrl.value == \"\") return (true); 
  56.     if (! checkInt(Ctrl.value, 10)) {
  57.         errorBox (Ctrl, \"The hop count must be a valid integer.\");
  58.         return (false);
  59.     }
  60.     num = parseInt(Ctrl.value); 
  61.         if (num > 16) {     
  62.         errorBox (Ctrl, \"The hop count must be less than 16.\"); 
  63.         return (false); 
  64.     } 
  65.     return (true);
  66. }
  67. function testAddress(Ctrl) {
  68.     if (Ctrl.value == \"\") return (true); 
  69.     if (!testIPaddress(Ctrl.value,false)) { 
  70.         errorBox (Ctrl, \"The network IP address \" + Ctrl.value 
  71.             + \" \\nis invalid.\"); 
  72.         return (false); 
  73.     }
  74.     return (true);
  75. }";
  76.  
  77.  
  78. print $query->header;
  79.  
  80. $enabled = &get_config("routed");
  81.  
  82. &getOptions;
  83.  
  84. if ($query->param) {
  85.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  86.     $help =~ s/cgi$/hlp/;
  87.     exec $help if ($query->param('help') eq "Help");
  88.  
  89.     if ($query->param('doit') eq 'Ok') {
  90.         if ($query->param('enable') eq 'Yes') {
  91.             &formValidation;
  92.             &writeOptions;
  93.             $message = "Completed changes.";
  94.         } else { &disable; }
  95.         if (!$message) { $message = "No changes made."; }
  96.     }
  97. }
  98.  
  99. &generic;
  100.  
  101. sub error {
  102.     &error_block($_[0]);
  103.     &generic;
  104.     exit 0;
  105. }
  106.  
  107. sub writeOptions {
  108.     open (OUT,"> $conf");
  109.     $value = "";
  110.  
  111.     if ($query->param('sflag') eq "Yes") { 
  112.         $d_sflag = "Yes";
  113.         $value = "s";
  114.     } else { $d_sflag = "No"; }
  115.  
  116.     if ($query->param('gflag') eq "Yes") { 
  117.         $d_gflag = "Yes";
  118.         $value .= "g";
  119.     } else { $d_gflag = "No"; }
  120.  
  121.     if ($query->param('qflag') eq "Yes") { 
  122.         $d_qflag = "Yes";
  123.         $value .= "q";
  124.     } else { $d_qflag = "No"; }
  125.  
  126.     if ($query->param('tflag') eq "Yes") { 
  127.         $d_tflag = "Yes";
  128.         $value .= "t";
  129.     } else { $d_tflag = "No"; }
  130.  
  131.     if ($query->param('hflag') eq "Yes") { 
  132.         $d_hflag = "No";
  133.         $value .= "h";
  134.     } else { $d_hflag = "Yes"; }
  135.  
  136.     if ($query->param('mflag') eq "Yes") { 
  137.         $d_mflag = "Yes";
  138.         $value .= "m";
  139.     } else { $d_mflag = "No"; }
  140.     
  141.     if ($value) {print OUT "-$value\n"; }
  142.  
  143.     if ($query->param('net')) {
  144.         print OUT "-F ",$query->param('net'),",",
  145.             $query->param('metric'),"\n";
  146.         $d_net = $query->param('net');
  147.         $d_metric = $query->param('metric');
  148.     } else { $d_net = ""; $d_metric = "14"; }
  149.  
  150.     if ($query->param('logf')) {
  151.         print OUT $query->param('logf'),"\n";
  152.         $d_logfile = $query->param('logf');
  153.     } else { $d_logfile = ""; }
  154.     
  155.     close(OUT);
  156.  
  157.     system("/etc/chkconfig", "routed", "on");
  158.     system("/etc/killall", "routed");
  159.         open(IN,"< /etc/config/routed.options");
  160.         while(<IN>) {
  161.             chop($_);
  162.             $configFile .= " $_";
  163.         }
  164.         close(IN);
  165.         system("/usr/etc/routed $configFile > /dev/null 2>&1");
  166.         $enabled = "Yes";
  167. }
  168.  
  169. sub disable {
  170.     if ($enabled eq 'Yes') {
  171.     system("/etc/chkconfig", "routed", "off");
  172.     system("/etc/killall", "routed");
  173.         $enabled = "No";
  174.         $message = "Dynamic routing disabled.";
  175.     }
  176. }
  177.  
  178.  
  179. sub getOptions {
  180.     $d_sflag = "No";
  181.     $d_qflag = "No";
  182.     $d_tflag = "No";
  183.     $d_gflag = "No";
  184.     $d_hflag = "Yes";
  185.     $d_mflag = "No";
  186.     $d_Fflag = "No";
  187.     $d_logfile = $dfl_logfile = "";
  188.     $d_metric = $dfl_metric = 14;
  189.     $d_net = "";
  190.  
  191.         open(OPTIONS, $conf) || print "Cannot open $conf";
  192.         while(<OPTIONS>) {
  193.         if (/^#/) { next; }
  194.         chop;
  195.         @optlist = split(/\s+/);
  196.         $i = 0;
  197.         while ($optlist[$i]) {
  198.                 if ($optlist[$i] =~ /^\//) {
  199.             $d_logfile = $optlist[$i];
  200.             last;
  201.                 }
  202.                 @chars = split(//, $optlist[$i]);
  203.                 if ($chars[0] eq "-") {
  204.             if ($chars[1] eq "F") {
  205.                     @flt = split(/\,/, $optlist[$i+1]);
  206.                     $d_net = $flt[0];
  207.                     if ($flt[1] ne "") { $d_metric = $flt[1]; }
  208.                     $i += 2;
  209.                     next;
  210.             } 
  211.             $j = 0;
  212.             while ($chars[++$j]) {
  213.                 if    ($chars[$j] eq "s") { $d_sflag = "Yes"; }
  214.                 elsif ($chars[$j] eq "q") { $d_qflag = "Yes"; }
  215.                 elsif ($chars[$j] eq "t") { $d_tflag = "Yes"; }
  216.                 elsif ($chars[$j] eq "g") { $d_gflag = "Yes"; }
  217.                 elsif ($chars[$j] eq "h") { $d_hflag = "No"; }
  218.                 elsif ($chars[$j] eq "m") { $d_mflag = "Yes"; }
  219.             }
  220.                 }
  221.                 $i++;
  222.         }
  223.     }
  224.     close(OPTIONS);
  225. }
  226.  
  227. sub formValidation {
  228.     if ($query->param('logf') && $query->param('logf') ne $d_logfile) {
  229.         my $errvar = &check_fname($query->param('logf'), 2);
  230.         &error($errvar) if $errvar; 
  231.     }
  232.  
  233.     $retNet = $query->param('net');
  234.     &error("Invalid IP address") if $retNet && &check_ipaddr($retNet);
  235.         
  236.     &error("Metric must be between $MINMETRIC and $MAXMETRIC")
  237.         if &check_int($query->param('metric'), $MINMETRIC, $MAXMETRIC);
  238. }
  239.  
  240. sub error {
  241.     &error_block($_[0]);
  242.     &generic;
  243.     exit 0;
  244. }   
  245.  
  246. sub generic {
  247.     &js_title_block($title,$js);
  248.     &header_block($title);
  249.  
  250.     open(IN,"/usr/OnRamp/bin/htnetwork | ");
  251.     $num = 0;
  252.     while(<IN>) {
  253.         @items = split(/:/);
  254.         if ($items[2] == 1) { $num++; }
  255.     }
  256.     close(IN);
  257.  
  258.     print "<i>$message</i>";
  259.  
  260.     print $query->startform("POST", "", "", "NAME=StandardForm", "onSubmit=\"return runSubmit()\"");
  261.  
  262.     print "<center><table cellpadding=5 width=450>\n";
  263.  
  264.     print "<tr><th align=left>Enable dynamic routing:\n",
  265.         "<th align=left>",
  266.               $query->radio_group(-name=>'enable',
  267.               -values=>['Yes','No'],
  268.               -default=>$enabled), "</tr>\n";
  269.  
  270.     print "<tr><th align=left>Offer default destination for unknown
  271.         routes:\n","<th align=left>",
  272.               $query->radio_group(-name=>'gflag',
  273.               -values=>['Yes','No'],
  274.               -default=>$d_gflag), "</tr>\n";
  275.  
  276.     if ($num == 1) {
  277.     print "<tr><th align=left>Force router to supply network
  278.         information:\n","<th align=left>",
  279.               $query->radio_group(-name=>'sflag',
  280.               -values=>['Yes','No'],
  281.               -default=>$d_sflag), "</tr>\n";
  282.     } else {
  283.     print "<tr><th align=left>Force router to suppress network
  284.         information:\n","<th align=left>",
  285.               $query->radio_group(-name=>'qflag',
  286.               -values=>['Yes','No'],
  287.               -default=>$d_qflag), "</tr>\n";
  288.     }
  289.  
  290.     print "<tr><th align=left>Print all inbound and outbound 
  291.         packets to standard output device:\n","<th align=left>",
  292.               $query->radio_group(-name=>'tflag',
  293.               -values=>['Yes','No'],
  294.               -default=>$d_tflag), "</tr>\n";
  295.  
  296.     print "<tr><th align=left>Advertise host routes 
  297.         on the primary interface:\n","<th align=left>",
  298.               $query->radio_group(-name=>'mflag',
  299.               -values=>['Yes','No'],
  300.               -default=>$d_mflag), "</tr>\n";
  301.  
  302.     print "<tr><th align=left>Advertise host 
  303.         routes on secondary interfaces:\n","<th align=left>",
  304.               $query->radio_group(-name=>'hflag',
  305.               -values=>['Yes','No'],
  306.               -default=>$d_hflag), "</tr>\n";
  307.  
  308.     print "</table><table width=450 cellpadding=5>\n";
  309.  
  310.     print "<tr><th align=left>Filename for logging routing events:
  311.             </th><th align=right>",
  312.               $query->textfield(-name=>'logf',
  313.             -default=>$d_logfile,
  314.             -size=>20, -maxlength=>256), "</th></tr>\n";
  315.  
  316.     print "</table><table width=450 cellpadding=5>\n";
  317.  
  318.     print "<tr><th align=left>Filter out routes to network ",
  319.         $query->textfield(-name=>'net', -default=>$d_net, -size=>15),
  320.         "\n and replace with a default route with hop count of: ",
  321.         $query->textfield(-name=>metric, -size=>3, -default=>$d_metric),
  322.         "</tr>\n";
  323.  
  324.     print "</table></font></center>";
  325.  
  326.      print "<br>\n";
  327.  
  328.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"',
  329.         "onClick=\"do_help('$help_page'); return (false)\"");
  330.  
  331.     print $query->endform;
  332. }
  333.